package com.transportation.app.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class AppUtils {

    public static String getAppVersion(Context context) {
        String versionName = "1.0.0";
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            versionName = packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            // 应用程序没有找到，这应该不会发生
            e.printStackTrace();
        }
        return versionName;
    }

    public static String getAppVersionCode(Context context) {
        String versionName = "1";
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            versionName = packageInfo.versionCode + "";
        } catch (PackageManager.NameNotFoundException e) {
            // 应用程序没有找到，这应该不会发生
            e.printStackTrace();
        }
        return versionName;
    }



    public static Double getPrice(String price) {
        try {
            Double number = Double.valueOf(price);
            double num = number.doubleValue();
            return num;
        } catch (Exception e) {
            return 0.0;
        }
    }

}
